<template>
    <div class="home">
        <div class="topbg"><img src="../../public/images/topbg.jpg" alt=""></div>
        <vue-particles
            class="particular"
            color="#3ca799"
            :particleOpacity="1"
            :particlesNumber="100"
            shapeType="circle"
            :particleSize="4"
            linesColor="#5675aa"
            :linesWidth="1"
            :lineLinked="true"
            :lineOpacity="0.8"
            :linesDistance="150"
            :moveSpeed="3"
            :hoverEffect="true"
            hoverMode="grab"
            :clickEffect="true"
            clickMode="repulse"
        ></vue-particles>
        <div class="search-center">
            <div class="animated fadeInDown">
                <h3>一站式教育科研知识服务</h3>
                <p>全方位、多维度科研大数据可视化检索</p>
            </div>
            <div class="search-div animated bounceIn">
                <form @submit="submitFn">
                    <div class="search-wrapper">
                        <div class="input-holder">
                            <Select v-model="select" style="width:100px" class="search-select" size="large" v-if="flag">
                                <Option v-for="item in searchList" :value="item" :key="item">{{ item }}</Option>
                            </Select>
                            <input type="text" class="search-input" placeholder="请输入关键词" v-model="search" />
                            <button class="search-icon" @click="searchToggle"><span></span></button>
                        </div>
                        <span class="close" @click="searchToggle"></span>
                        <div class="result-container" v-if="!search">{{!search&&'输入关键词不能为空'}}</div>
                    </div>
                </form>
            </div>
        </div>
        <div class="ai-assistant" @click="model=true">
            <img src="../../public/images/logo.png" alt="">
            <div>EduDMiner</div>
        </div>
        <Modal v-model="model" scrollable :mask="false" class="ai-model">
            <p slot="header">
                <img src="../../public/images/logo.jpg" alt="" width="50px" style="vertical-align:middle">
                <span style="vertical-align:middle">EduDMiner</span>
            </p>
            <div>
                <AI-dialog  
                :dialogConfig.sync="dialogConfig"
                @response="response"
                />
            </div>
            <div slot="footer" class="input-model">
                <div class="textarea">
                    <textarea @keydown="handleKeyCode($event)" placeholder="输入关键词" name="" id="" cols="30" rows="10" v-model="input"></textarea>
                    <img @click="send" class="send" src="../assets/send.png" alt="" />
                </div>
            </div>
        </Modal>
    </div>
</template>

<script>
import AIDialog from '../components/AIdialog.vue';
export default {
    components:{
        'AI-dialog':AIDialog
    },
    data(){
        return{
            select:'论文',
            searchList:['论文','期刊','政策','专利','会议','项目'],
            flag:false,
            search:'',
            model:false,
            test:false,
            input:'',
            dialogConfig:{
                hot_list:['目前比较热门的研究领域有哪些？','教育技术领域的会议有哪些？','华中师范大学有哪些学者？','关键词包含“教育”的论文有哪些？','关键词包含“教育”的项目有哪些？'],
                message_list:[]
            }
        }
    },
    mounted() {
        this.$Loading.finish();
    },

    methods: {
        searchToggle(evt){
            let obj = evt.currentTarget;
            var container = $(obj).closest('.search-wrapper');
            if(!container.hasClass('active')){
                container.addClass('active');
                evt.preventDefault();
                this.flag = true;
            }
            else if(container.hasClass('active') && $(obj).closest('.input-holder').length == 0){
                container.removeClass('active');
                container.find('.search-input').val('');
                container.find('.result-container').fadeOut(100, function(){$(this).empty();});
                this.flag = false;
            }
        },
        submitFn(evt){
            let obj = evt.currentTarget;
            evt.preventDefault();
            $(obj).find('.result-container').fadeIn(100);
            switch(this.select){
                case '论文':
                    this.$router.push({
                        name:'PaperSearch',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
                case '期刊':
                    this.$router.push({
                        name:'Journal',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
                case '政策':
                    this.$router.push({
                        name:'Policy',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
                case '专利':
                    this.$router.push({
                        name:'Patent',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
                case '会议':
                    this.$router.push({
                        name:'Conference',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
                case '项目':
                    this.$router.push({
                        name:'Project',
                        params:{
                            searchKey:this.search
                        }
                    });
                    break;
            }
        },
        //AI对话响应函数
        response(newVal){
            let response = newVal.message_list[newVal.message_list.length-1];
            if(response.type=='text'){
                //调用ajax
                let searchContent = response.content;
                console.log('调用ajax',searchContent);
            }
        },
        //输入框发送文本
        send(){
            if(this.input.trim()=='') return;
            this.dialogConfig.message_list.push({
                type:'text',
                author:'user',
                content:this.input
            });
            this.input = '';
        },
        // 键盘回车事件
        handleKeyCode(e) {
            if(e.keyCode == 13 && e.ctrlKey){
                this.input += "\n"; //换行
            }else if(e.keyCode == 13){
                this.send(); //提交的执行函数
                e.preventDefault();//禁止回车的默认换行
            }
        },
    },
}
</script>

<style lang="scss" scoped>
.input-model{
    text-align: left;
    textarea{
        height: 14vh;
        width: 40vw;
    }
    textarea::-webkit-scrollbar{  
        display: none;
    }  

}
 .input-container{
    display: flex;
    flex-direction: row;
    justify-content: left;
    align-items: center;
    margin-top: 5vh;
}
.input-container .textarea{
    height: 9vh;
    width: 60%;
    margin-left: 1%;
    background: #2b2a2e;
    border-radius: 5px;
    box-shadow: 0 6px 17px rgba(0, 0, 0, 0.3);
    padding-right: 10%;

}
.textarea{
    position: relative;
}
.textarea textarea{
    width: 60%;
    padding:10px;
    padding-left: 20px;
    border: 0;
    font-size: 14px;
    border: none;
    background: none;
    outline: none;
    resize:none;
    border: 1px solid #ddd;
    border-radius: 15px;
    transition: all 0.2s ease;
}
.textarea textarea:hover{
    border: 1px solid #73b1e4;
}
.textarea .send{
    position: absolute;
    left: calc(60% + 20px);
    width: 50px;
    bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #73b1e4;
    padding: 12px;
    border-radius: 100%;
}
.send:hover{
    opacity: .9; 
}
/deep/ .ivu-modal{
    top:20px !important;
}
/deep/ .ivu-modal-content{
    width: 68vw !important;
    height: 95vh !important;
    left: 50% !important;
    top: 0px !important;
    transform: translateX(-50%) !important;
}
/deep/ .ivu-modal-no-mask,.ivu-modal-wrap{
    overflow: hidden !important; 
}
/deep/ .ivu-tabs-nav{
    left: 50%;
    transform: translateX(-50%);
}
/deep/ .ivu-modal-body{
    padding: 0 !important;
}
.home{
  overflow-x: hidden;
  position: relative;
  width: 100%;
  height: 100vh;
  background: linear-gradient(-150deg,#1c4f48,#28354b);
  padding-bottom: 50px;

  .search-select{
      position: absolute;
      left: 20px;
      top: 50%;
      transform: translateY(-50%);
      z-index: 99;
      border-radius: 100px;
      /deep/ .ivu-select-selection{
          border-radius: 100rem;
          border: 2px solid white;
          width: 110px;
      }
      /deep/ .ivu-select-dropdown{
          max-height: 300px;
      }
  }
  .topbg{
      position: absolute;
      width: 100%;
      height: 100%;
      padding-bottom: 50px;
      overflow: hidden;
      opacity: .5;
  }
  h3{
      color:white;
      font-weight: normal;
      font-size: 50px;
      margin-bottom: 20px;
      text-shadow: 1px 3px 5px #303030;
  }
  p{
      color: white;
      font-size: 25px;
      text-shadow: 1px 3px 5px #303030;
  }
  .particular{
    position: absolute;
    overflow: hidden;
    z-index: 0;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    // background: url(../../public/images/topbg.jpg);
    // opacity: .4;
  }
  .search-center{
      position: absolute;
      width: 100%;
      top: 40%;
      left: 50%;
      transform: translateX(-50%) translateY(-50%);
  }
  .ai-assistant{
      position: absolute;
      bottom: 100px;
      right: 0;
      color: white;
      background: rgba(53, 53, 53, 0.371);
      padding: 12px;
      border-top-left-radius: 10px;
      border-bottom-left-radius: 10px;
      cursor: pointer;
      font-size: 13px;
      img{
          width: 60px;
      }
  }
}
.search-wrapper {
    position: absolute;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    top:50%;
    left:50%;
    margin-top: 60px;
}

.search-wrapper .input-holder {
    // overflow: hidden;
    height: 70px;
    background: rgba(255,255,255,0);
    border-radius:6px;
    position: relative;
    width:150px;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder {
    border-radius: 50px;
    width:40vw;
    background: rgba(0,0,0,0.5);
    -webkit-transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    -moz-transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    
}

.search-wrapper .input-holder .search-input {
    width:100%;
    height: 50px;
    padding:0px 70px 0 150px;
    opacity: 0;
    position: absolute;
    top:0px;
    left:0px;
    background: transparent;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    border:none;
    outline:none;
    font-family:"Open Sans", Arial, Verdana;
    font-size: 16px;
    font-weight: 400;
    line-height: 20px;
    color:#FFF;
    -webkit-transform: translate(0, 60px);
    -moz-transform: translate(0, 60px);
    transform: translate(0, 60px);
    -webkit-transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    -moz-transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);

    -webkit-transition-delay: 0.3s;
    -moz-transition-delay: 0.3s;
    transition-delay: 0.3s;
}
.search-wrapper.active .input-holder .search-input {
    opacity: 1;
    -webkit-transform: translate(0, 10px);
    -moz-transform: translate(0, 10px);
    transform: translate(0, 10px);
}

.search-wrapper .input-holder .search-icon {
    width:150px;
    height:70px;
    border-radius: 10rem;
    border:none;
    background: #FFF;
    padding:0px;
    outline:none;
    position: relative;
    z-index: 2;
    float:right;
    cursor: pointer;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder .search-icon {
    width: 50px;
    height:50px;
    margin: 10px;
    border-radius: 30px;
}
.search-wrapper .input-holder .search-icon span {
    width:22px;
    height:22px;
    display: inline-block;
    vertical-align: middle;
    position:relative;
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    transform: rotate(45deg);
    -webkit-transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);
    -moz-transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);
    transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);

}
.search-wrapper.active .input-holder .search-icon span {
    -webkit-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
.search-wrapper .input-holder .search-icon span::before, .search-wrapper .input-holder .search-icon span::after {
    position: absolute;
    content:'';
}
.search-wrapper .input-holder .search-icon span::before {
    width: 4px;
    height: 11px;
    left: 9px;
    top: 18px;
    border-radius: 2px;
    background: #5675aa;
}
.search-wrapper .input-holder .search-icon span::after {
    width: 14px;
    height: 14px;
    left: 0px;
    top: 0px;
    border-radius: 16px;
    border: 4px solid #3ca799;
}

.search-wrapper .close {
    position: absolute;
    z-index: 1;
    top:24px;
    right:20px;
    width:25px;
    height:25px;
    cursor: pointer;
    -webkit-transform: rotate(-180deg);
    -moz-transform: rotate(-180deg);
    transform: rotate(-180deg);
    -webkit-transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
    -moz-transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
    transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
    -webkit-transition-delay: 0.2s;
    -moz-transition-delay: 0.2s;
    transition-delay: 0.2s;
}
.search-wrapper.active .close {
    right:-50px;
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    transform: rotate(45deg);
    -webkit-transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    -moz-transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    -webkit-transition-delay: 0.5s;
    -moz-transition-delay: 0.5s;
    transition-delay: 0.5s;
}
.search-wrapper .close::before, .search-wrapper .close::after {
    position:absolute;
    content:'';
    background: #FFF;
    border-radius: 2px;
}
.search-wrapper .close::before {
    width: 5px;
    height: 25px;
    left: 10px;
    top: 0px;
}
.search-wrapper .close::after {
    width: 25px;
    height: 5px;
    left: 0px;
    top: 10px;
}
.search-wrapper .result-container {
    width: 100%;
    position: absolute;
    top:80px;
    left:0px;
    text-align: center;
    font-family: "Open Sans", Arial, Verdana;
    font-size: 14px;
    display:none;
    color:#ddd;
}

@media (max-width:1060px) {
    .search-wrapper.active .input-holder{
        width: 80vw;
    }
    /deep/ .ivu-select-selection{
        width: 80px !important;
        font-size: 14px;
    }
    .search-wrapper.active .close{
        display: none;
    }
    .search-wrapper .input-holder .search-input{
        padding: 0px 70px 0 120px;
    }
    .home h3{
        font-size: 25px;
        text-shadow: 1px 3px 5px #303030;
    }
    .home p{
        font-size: 20px;
        text-shadow: 1px 3px 5px #303030;
    }
    .search-jh img{
        width: 100px;
    }
}   
</style>